package com.xmy.study.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.study.entity.PerStudentClassType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * <p>
 * 权限表 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2023-06-25
 */
@Mapper
public interface PerStudentClassTypeMapper extends BaseMapper<PerStudentClassType> {
    @Select("SELECT " +
            "sg.id," +
            "sg.school_id," +
            "sg.student_id," +
            "sg.grade_id," +
            "tg.teacher_id," +
            "(SELECT `name` FROM xmy_erp_db.staff WHERE id = tg.teacher_id AND deleted = 0 LIMIT 1) AS teacherName," +
            "sg.year_part," +
            "sg.quarter_num," +
            "sg.subjects_id," +
            "sg.class_type_id_new AS classTypeId," +
            "sg.year_class_id," +
            "sg.`status`," +
            "sg.reading_status," +
            "sg.created_at " +
            "FROM " +
            "xmy_erp_db.student_grade AS sg " +
            "INNER JOIN xmy_erp_db.grade AS tg ON tg.id = sg.grade_id " +
            "WHERE " +
            "sg.deleted = 0 " +
            "AND sg.subjects_id = ${rs.subjectsId} " +
            "AND sg.quarter_num = ${rs.quarterNum} " +
            "AND sg.year_part = ${rs.yearPart} " +
            "AND sg.student_id = ${rs.studentId} " +
            "AND sg.lesson_type = 1 " +
            "AND sg.`status` <> 3 " +
            "AND sg.is_last = 1 " +
            "ORDER BY " +
            "sg.created_at DESC " +
            "LIMIT 1 ")
    public abstract PerStudentClassType getPerStudentClassType(@Param("rs") PerStudentClassType perStudentClassType);
}
